package com.fanfanwang.ffw.app.asynctask;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.LinkedHashMap;


import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.bean.SucChksmsBean;
import com.fanfanwang.ffw.app.bean.SucGetUserInfoBean;
import com.fanfanwang.ffw.app.bean.SucIsRegBean;
import com.fanfanwang.ffw.app.bean.SucLoginBean;
import com.fanfanwang.ffw.app.bean.SucRegBean;
import com.fanfanwang.ffw.app.bean.SucSetNewPasswordBean;
import com.fanfanwang.ffw.app.bean.SucSetPasswordBean;
import com.fanfanwang.ffw.app.bean.SucUpdateMobileBean;
import com.fanfanwang.ffw.app.bean.SucUpdateUserinfoBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;
import com.fanfanwang.ffw.app.ui.login.FindPwdAct;
import com.fanfanwang.ffw.app.ui.login.RegisterAct;

import android.app.Activity;
import android.text.TextUtils;


public class SetNewPasswordAsyncTask extends IssAsyncTask<String, String, SucSetNewPasswordBean> {
	private Activity mActivity;
	private String username;
	private String password;
	public SetNewPasswordAsyncTask(Activity activity,String username,String password) {
		super(activity);
		mActivity = activity;
		this.username = username;
		this.password=password;
	}

	@Override
	protected SucSetNewPasswordBean doInBackground(String... params) {
		// TODO 	addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucSetNewPasswordBean bean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("username", username);
		paramsMap.put("password", Md5Util.getMD5To32(password));
		try {
			bean = IssNetLib.getInstance(mActivity).setNewPassword(WebServiceHelper._SETNEWPASSWORD, paramsMap);
		} catch (HttpRequestException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//						exception = getResources().getString(R.string.e_net_error);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_json);
		}
		return bean;
	}

	@Override
	protected void onPostExecute(SucSetNewPasswordBean result) {
		super.onPostExecute(result);
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {
				try {
					ToastAlone.showToast(mActivity, URLDecoder.decode(result.msg,"utf-8"), ToastAlone.LENGTH_SHORT);
					FindPwdAct.iSetNewPasswordable.setNewPasswordSuccess();
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}else if(result.status == 0){
				FindPwdAct findPwdAct=new FindPwdAct();
				if(result.msg != null && !TextUtils.isEmpty(result.msg)){
					//					LogUtil.e(RegisterAct.this+"", result.msg);
					try {
						ToastAlone.showToast(mActivity, URLDecoder.decode(result.msg,"utf-8"), ToastAlone.LENGTH_SHORT);
					} catch (UnsupportedEncodingException e) {
						e.printStackTrace();
					}
				}else {
					ToastAlone.showToast(mActivity, findPwdAct.getResources().getString(R.string.e_net_error), ToastAlone.LENGTH_SHORT);
				}
			}
		}
	}
}
